package com.invengo.module_robot.ui.fragment.popular.item;

import android.text.TextUtils;
import android.view.TextureView;

import androidx.annotation.NonNull;

import com.invengo.module_robot.data.entity.PopularBean;
import com.invengo.module_robot.data.entity.TempBookBean;
import com.invengo.module_robot.ui.fragment.popular.PopularViewModel;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

/**
 * @author buoker
 * @version 1.0.0
 * @date 2024/03/20
 * @className java.lang.String
 */
public class PopularItemViewModel extends ItemViewModel<PopularViewModel> {
    public SingleLiveEvent<String> image = new SingleLiveEvent<>();
    public SingleLiveEvent<String> publisher = new SingleLiveEvent<>();
    public SingleLiveEvent<String> bookName = new SingleLiveEvent<>();

    public SingleLiveEvent<Boolean> largeName = new SingleLiveEvent<>();
    private TempBookBean bean;

    /**
     * 流行项目视图模型
     *
     * @param viewModel 视图模型
     * @param bean      豆
     */
    public PopularItemViewModel(@NonNull PopularViewModel viewModel, TempBookBean bean) {
        super(viewModel);
        this.bean = bean;
        image.postValue(bean.getImage());
        bookName.postValue(bean.getBookName());
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(bean.getAuthor())) {
            sb.append(bean.getAuthor());
        }
        if (!TextUtils.isEmpty(bean.getPublisher())) {
            sb.append(" | ");
            sb.append(bean.getPublisher());
        }
        if (!TextUtils.isEmpty(bean.getPubDate())) {
            sb.append(" | ");
            sb.append(bean.getPubDate());
        }
        publisher.postValue(sb.toString());
        largeName.postValue(bean.getBookName().length() >6);
    }

    /**
     * 单击命令
     */
    public BindingCommand clickCommand = new BindingCommand(() -> {
        viewModel.launchInfo(bean);
    });

    /**
     * 获取书豆
     *
     * @return {@link TempBookBean}
     */
    public TempBookBean getBookBean() {
        return bean;
    }
}
